<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ChangeCourse_Page</title>
<script src="../jquery-3.5.1.js"></script>
<script src="../jquery.cookie.js"></script>
<script>
	var userid = sessionStorage.getItem('testKey');
	console.log(userid);
	if (userid == null || userid == "") {
		window.location = "/login.html";
	}
</script>
<style>
body {
	font-size: 75%;
	font-family: verdana, arial, 'sans serif';
	background-repeat: repeat-x;
	background-color: #FFFFF0;
}

h1 {
	font-size: 200%;
}

h2 {
	font-size: 140%;
}

h3 {
	font-size: 110%;
}

th {
	background-color: #ADD8E6;
}

ol {
	list-style: upper-roman;
}

ul {
	list-style-type: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	background-color: #333;
}

li {
	float: left;
}

li a {
	display: block;
	color: white;
	text-align: center;
	padding: 14px 16px;
	text-decoration: none;
}

li a:hover {
	background-color: #111;
}

.active {
	background-color: #bfbfbf;
}

.foot {
	position: fixed;
	bottom: 5px;
	text-align: center;
	padding: 10px;
	border-radius: 6px;
	background-image: linear-gradient(to bottom right, #ffb21a, #ffdd99);
}
</style>

<script type="text/javascript">
	var url = decodeURI(window.location.href);
	var argsIndex = url.split("?courseTchId=");
	var ctid = argsIndex[1];
	console.log(ctid);
	window.onload = function() {
		$.ajax({
			type : 'GET',
			url : "/courseSelectionById/" + ctid,
			contentType : "application/json;cherset=utf-8",
			success : function(data) {
				console.log(data);
				var InData = data;
				for (var i = 0; i < data.courseTeaching.composition.length; i++) {
					/*$("#name" + i).text(
						data.courseTeaching.composition[i].partName
						+ ":");
					$("#max" + i).text(
						"满分"
						+ data.courseTeaching.composition[i].score);
					setScore(i,
						data.id,
						data.courseTeaching.composition[i].id);*/
					$("#fm").append("<form>"
									+"<b>"+data.courseTeaching.composition[i].partName+":</b>"
									+"<b>满分"+ data.courseTeaching.composition[i].score+"</b>"
									+'<input type="text" name="subScore"><br/>'
									+'<input value="'+data.id+'" name=courseSelectionId type="hidden"/>'
									+'<input value="'+data.courseTeaching.composition[i].id+'" name="scoreCompositionId" type="hidden"/>'
									+"</form>");

				}
				$("#fm").append('<button type="button" onclick="setScore()">提交</button>');
			},
			error : function(data) {
				alert("error:" + JSON.stringify(data));
			}
		});

	}
	/*function setScore(i, Csid, Scid) {
		function conf(i, Csid, Scid) {

			var score = $("#part" + i).val();

			$.post("/studentSubScore", {
				subScore : score,
				courseSelectionId : Csid,
				scoreCompositionId : Scid
			}, function(data) {
				alert("录入成功")
				console.log(data);

			})
		}

	}*/
	function setScore(){
		$("#fm").children("form").each(function(){
			$.post("/studentSubScore",$(this).serialize(),function(data){
				console.log(data);
			})
		});
	}
</script>

</head>
<body>
	<ul>
		<!--导航栏 -->
		<li><a href="TeacherPage.html">主页</a></li>
		<li><a href="TchCourses.html">查看所教课程</a></li>
		<li><a class="active" href="LoggingScore.html">分数录入</a></li>
		<li><a href="AddCourse.html">增加课程</a></li>
		<li style="float: right"><a href="">修改密码</a></li>

	</ul>
	<br />
	<em>请输入各部分分数</em>
	<br />
	<div id="fm">
		<!--<b id="name0"></b> <b id="max0"></b> <input type="text" id="part0"><br/> 
		<b id="name1"></b> <b id="max1"></b> <input type="text" id="part1"><br/>
		<button type="button" onclick="setScore()">提交</button>-->
	</div>
</body>
</html>